using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Collections;
using NovodexWrapper;

namespace marbletrack
{
    static class MathConversion
    {
        // Converts NxVec3 to Vector3
        public static Vector3 ToVector3(NxVec3 nxVec3)
        {
            return new Vector3(nxVec3.x, nxVec3.y, nxVec3.z);
        }

        // Converts Vector3 to NxVec3
        public static NxVec3 ToNxVec3(Vector3 vector3)
        {
            return new NxVec3(vector3.X, vector3.Y, vector3.Z);
        }

        // Converts NxMat34 to Matrix
        public static Matrix ToMatrix(NxMat34 nxMat34)
        {
            Matrix result = Matrix.Identity;
            result.M11 = nxMat34.M.M11;
            result.M12 = nxMat34.M.M12;
            result.M13 = nxMat34.M.M13;
            result.M21 = nxMat34.M.M21;
            result.M22 = nxMat34.M.M22;
            result.M23 = nxMat34.M.M23;
            result.M31 = nxMat34.M.M31;
            result.M32 = nxMat34.M.M32;
            result.M33 = nxMat34.M.M33;
            result.Translation = ToVector3(nxMat34.t);
            return result;
        }

        // Converts Matrix to NxMat34
        public static NxMat34 ToNxMat34(Matrix matrix)
        {
            NxMat34 result = NxMat34.Identity;
            result.M.M11 = matrix.M11;
            result.M.M12 = matrix.M12;
            result.M.M13 = matrix.M13;
            result.M.M21 = matrix.M21;
            result.M.M22 = matrix.M22;
            result.M.M23 = matrix.M23;
            result.M.M31 = matrix.M31;
            result.M.M32 = matrix.M32;
            result.M.M33 = matrix.M33;
            result.t = ToNxVec3(matrix.Translation);
            return result;
        }

        //Convert Matrix to NxMat33
        public static Matrix NxMat33ToMatrix(NxMat33 nxMat33)
        {
            Matrix result = Matrix.Identity;
            result.M11 = nxMat33.M11;
            result.M12 = nxMat33.M12;
            result.M13 = nxMat33.M13;
            result.M21 = nxMat33.M21;
            result.M22 = nxMat33.M22;
            result.M23 = nxMat33.M23;
            result.M31 = nxMat33.M31;
            result.M32 = nxMat33.M32;
            result.M33 = nxMat33.M33;
            return result;
        }

        // Converts Matrix to NxMat33
        public static NxMat33 ToNxMat33(Matrix matrix)
        {
            NxMat33 result = NxMat33.Identity;
            result.M11 = matrix.M11;
            result.M12 = matrix.M12;
            result.M13 = matrix.M13;
            result.M21 = matrix.M21;
            result.M22 = matrix.M22;
            result.M23 = matrix.M23;
            result.M31 = matrix.M31;
            result.M32 = matrix.M32;
            result.M33 = matrix.M33;
            return result;
        }

        // Extracts position data from VertexPositionNormalTexture
        public static NxVec3[] ExtractVertexBuffer(VertexPositionNormalTexture[] vertexPositionNormalTextures)
        {
            NxVec3[] vertexBuffer = new NxVec3[vertexPositionNormalTextures.Length];

            int i = 0;
            foreach (VertexPositionNormalTexture vertexPositionNormalTexture in vertexPositionNormalTextures)
            {
                vertexBuffer[i] = ToNxVec3(vertexPositionNormalTexture.Position);
                i++;
            }

            return vertexBuffer;
        }
    }
}
